﻿using System;
using CommonPatterns.IoC;
using CommonPatterns.MVVM;
using Microsoft.Practices.Unity;
using OCDP.Client.Screens.CocoScreen;
using OCDP.Client.Screens.DatabasesBrowser;
using OCDP.Client.Screens.ToolBox;
using OCDP.Client.Screens.WorkSpace;
using OCDP.Client.Services.Clock;
using System.Windows;
using OCDP.Client.Screens.ClockScreen;
using CommonPatterns.Screen;
using OCDP.Client.Screens.Hello;

namespace OCDP.Client
{
    [MenuItem("_OCDPModule")]
    public class OCDPModule : IModule
    {
        #region Implementation of IModule

        public void Register(IUnityContainer container)
        {
            container.RegisterType<IClockService, ClockService>();

            // registering mvvm components
            container.RegisterMvvmUnit<DatabasesExplorerView, DatabasesExplorerViewModel, IDatabasesExplorerViewModel>(true);
            container.RegisterMvvmUnit<ToolBoxView, ToolBoxViewModel, IToolBoxViewModel>(true);
            container.RegisterMvvmUnit<WorkSpaceView, WorkSpaceViewModel, IWorkSpaceViewModel>(true);
            container.RegisterMvvmUnit<CocoScreenView, CocoScreenViewModel, ICocoScreenViewModel>(true);
            container.RegisterMvvmUnit<ClockScreenView, ClockScreenViewModel, IClockScreenViewModel>(true);
            container.RegisterMvvmUnit<HelloView, HelloViewModel, IHelloViewModel>(true);

            LoadDictionaryRessources("OCDP.Client;component/Resources/Bank.xaml");
        }

        private static void LoadDictionaryRessources(string path)
        {
            var t = new Uri(path, UriKind.Relative);
            var dic = Application.LoadComponent(t) as ResourceDictionary;
            Application.Current.Resources.MergedDictionaries.Add(dic);
        }
        #endregion
    }
}
